package com.bawei.composeui2207a.model

import com.zyj.retrofit.adapter.FlowCallAdapterFactory
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

/**
 * 作者：赵亮
 * 时间：2024/12/12 12:03
 * 功能：网络工具类
 */
object RetrofitManager {

    private val client = OkHttpClient.Builder()
        .connectTimeout(5, TimeUnit.MINUTES)
        .readTimeout(5, TimeUnit.MINUTES)
        .writeTimeout(5, TimeUnit.MINUTES)
        .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
        .addInterceptor { chain ->
            chain.proceed(chain.request().newBuilder()
                .addHeader("token", "token")
                .addHeader("sign", "sign")
                .build())
        }
        .build()

    private val retrofit = Retrofit.Builder()
        .baseUrl("http://0/")
        .client(client)
        .addConverterFactory(GsonConverterFactory.create())
        .addCallAdapterFactory(FlowCallAdapterFactory.create())
        .build()

    val apiService = retrofit.create(ApiService::class.java)
}